import { View } from "../../../mvc/core/View";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { EffectManager } from "../../manager/EffectManager";
import { UIIconEvent } from "./UIIconEvent";
import { SActiveToClient } from "../../../../Message/Public/SActiveToClient";
import { Cache } from "../../cache/Cache";
import { JSONHelper } from "../../../../com/mui/serialization/json/JSONHelper";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
//class HintIcon
    
    export  class HintIcon extends View
    {
        constructor(arg1: string=null, arg2: Boolean=true)
        {
            super();
            this._imageName = arg1;
            this._clickHide = arg2;
            if (this._imageName) 
            {
                this.createChindren();
            }
            return;
        }

        public set labelTxt(arg1: string)
        {
            if (!this._labelTxt) 
            {
                this.createLabel();
            }
            this._labelTxt.text = arg1;
            return;
        }

        protected createLabel(): void
        {
            this._labelTxt = new Object /* flash.text.TextField */();
            var loc1=new GTextFormat(FontUtil.songtiName, 10, 16777215);
            this._labelTxt.defaultTextFormat = loc1;
            this._labelTxt.selectable = false;
            this._labelTxt.mouseEnabled = false;
            this._labelTxt.filters = [FilterConst.glowFilter];
            this._labelTxt.width = this._hintIcon.width;
            this._labelTxt.height = 10;
            this._labelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._labelTxt.y = this._hintIcon.height - 14;
            addChild(this._labelTxt);
            return;
        }

        protected createChindren(): void
        {
            this._hintIcon = new Object /* flash.display.Sprite */();
            this._hintIcon.addChild(GlobalClass.getScaleBitmap(this._imageName));
            addChild(this._hintIcon);
            this._hintIcon.buttonMode = true;
            this._hintIcon.addEventListener(flash.events.MouseEvent.CLICK, this.onHintIconClickHandler);
            return;
        }

        protected onHintIconClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            EffectManager.glowFilterUnReg(this);
            if (this.parent && this._clickHide) 
            {
                this.parent.removeChild(this);
                this.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
            }
            return;
        }

        public updateActiveToClientInfo(arg1: SActiveToClient): void
        {
            var loc5=null;
            var loc1=false;
            if (arg1) 
            {
                loc1 = Cache.instance.active.isActiveInEffect(arg1.code);
            }
            if (arg1 == null || !loc1) 
            {
                if (this._imageBmp && this._imageBmp.parent) 
                {
                    removeChild(this._imageBmp);
                }
                if (this._multipTxt) 
                {
                    this._multipStr = "";
                    this._multipTxt.htmlText = "";
                }
                return;
            }
            var loc2=arg1.modulus;
            var loc3=0;
            var loc4=0;
            if (loc2 && !(loc2 == "")) 
            {
                if ((loc5 = JSONHelper.deserialize(loc2)) && loc5.hasOwnProperty("min")) 
                {
                    loc4 = loc5["min"];
                }
                if (loc5 && loc5.hasOwnProperty("max")) 
                {
                    loc3 = loc5["max"];
                }
            }
            if (loc4 > 0 || loc3 > 0) 
            {
                if (this._imageBmp == null) 
                {
                    this._imageBmp = new GImageBitmap(ImagesConst.ActiveBubbleBg, 0, 0);
                    this._imageBmp.y = -26;
                }
                addChild(this._imageBmp);
                if (this._multipTxt == null) 
                {
                    this._tf = new GTextFormat(FontUtil.EmbedNumberName, 14, 16776960, null, null, null, null, null, flash.text.TextFieldAutoSize.RIGHT);
                    this._multipTxt = ObjCreate.createGTextField("", -5, 0, 40, 20, this, this._tf);
                    this._multipTxt.y = -23;
                    this._multipTxt.embedFonts = true;
                }
                addChild(this._multipTxt);
                this._multipStr = "×" + loc4;
                if (loc3 > loc4) 
                {
                    this._multipStr = this._multipStr + "-" + loc3;
                }
                this._multipTxt.htmlText = this._multipStr;
            }
            else 
            {
                if (this._imageBmp && this._imageBmp.parent) 
                {
                    removeChild(this._imageBmp);
                }
                if (this._multipTxt) 
                {
                    this._multipStr = "";
                    this._multipTxt.htmlText = "";
                }
            }
            return;
        }

        /* internal  */resetMultipTxt(): void
        {
            if (this._multipTxt) 
            {
                this._multipTxt.setTextFormat(this._tf);
                this._multipTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
                this._multipTxt.htmlText = this._multipStr;
            }
            return;
        }

        protected /* var */_imageName: string;

        protected /* var */_hintIcon: Object /* flash.display.Sprite */;

        protected /* var */_clickHide: Boolean;

        protected /* var */_labelTxt: Object /* flash.text.TextField */;

        protected /* var */_sActiveToClient: SActiveToClient;

        protected /* var */_imageBmp: GImageBitmap;

        protected /* var */_multipTxt: GTextFiled;

        protected /* var */_tf: GTextFormat;

        protected /* var */_multipStr: string="";
    }
